<?php

namespace App\Admin\Controllers;

use App\Models\Conversion;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ConversionsController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '转换管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Conversion);
        $grid->model()->orderBy('created_at','desc');
        $grid->column('id', __('Id'));
        $grid->column('btc', __('转换btc数量'));
        $grid->column('balance', __('转换金额'));
        $grid->column('btc_price', __('比特币价格'));
        $grid->column('status', __('状态'))->display(function ($status) {
            return config('conf.status')[$status];
        });
        $grid->column('user.username', __('用户名'));
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('修改时间'));
        $grid->disableCreateButton();
        $grid->actions(function ($actions) {
            $actions->disableDelete();
            $actions->disableView();

        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Conversion::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('btc', __('Btc'));
        $show->field('balance', __('Balance'));
        $show->field('btc_price', __('Btc price'));
        $show->field('status', __('Status'));
        $show->field('user_id', __('User id'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Conversion);

        $form->decimal('btc', __('转换btc数量'));
        $form->decimal('balance', __('转换金额'));
        $form->decimal('btc_price', __('比特币价格'));
        $form->select('status', __('状态'))->options(config('conf.status'));
        $form->number('user_id', __('用户名'));

        return $form;
    }
}
